// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   SET_IIImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.II;
import com.sunwayhorizo.health.hl7.datatypes.IVL_II;
import com.sunwayhorizo.health.hl7.datatypes.SET_II;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            SETCommonImpl, ANYImpl, BLImpl, CSImpl, 
//            TYPEImpl

public class SET_IIImpl extends SETCommonImpl
    implements SET_II
{

    public static final String RCS_ID = "$Header: SET_IIImpl.java 115.24 2005/09/16 09:22:51 amchanda noship $";
    private static final SET_II nullNI = new SET_IIImpl(CSImpl.valueOf("NI"));
    private static final SET_II nullOTH = new SET_IIImpl(CSImpl.valueOf("OTH"));
    private static final SET_II nullNINF = new SET_IIImpl(CSImpl.valueOf("NINF"));
    private static final SET_II nullPINF = new SET_IIImpl(CSImpl.valueOf("PINF"));
    private static final SET_II nullUNK = new SET_IIImpl(CSImpl.valueOf("UNK"));
    private static final SET_II nullASKU = new SET_IIImpl(CSImpl.valueOf("ASKU"));
    private static final SET_II nullNAV = new SET_IIImpl(CSImpl.valueOf("NAV"));
    private static final SET_II nullMSK = new SET_IIImpl(CSImpl.valueOf("MSK"));
    private static final SET_II nullNA = new SET_IIImpl(CSImpl.valueOf("NA"));
    private static final SET_II nullNASK = new SET_IIImpl(CSImpl.valueOf("NASK"));

    public static SET_II valueOf(II aii[])
    {
        return new SET_IIImpl(aii);
    }

    public static SET_II valueOf(II ii)
    {
        return new SET_IIImpl(ii);
    }

    public static SET_II valueOf(Set set)
    {
        return new SET_IIImpl(set);
    }

    public static SET_II nullSET_II()
    {
        return new SET_IIImpl(((CS) (null)));
    }

    protected SET_IIImpl(II aii[])
    {
        if(aii == null)
            throw ANYImpl.newNullException("SET<II>", "constructor", "elements");
        for(int i = 0; i < aii.length; i++)
            if(aii[i] != null && aii[i].isNull().isFalse())
                mSet.add(aii[i]);

    }

    protected SET_IIImpl(II ii)
    {
        if(ii == null || ii.isNull().isTrue())
        {
            throw ANYImpl.newNullException("SET<II>", "constructor", "element");
        } else
        {
            mSet.add(ii);
            return;
        }
    }

    protected SET_IIImpl(Set set)
    {
        super(set);
    }

    protected SET_IIImpl(CS cs)
    {
        super(cs);
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.SET_II;
    }

    public BL contains(II ii)
    {
        return BLImpl.valueOf(mSet.contains(ii));
    }

    public BL contains(SET_II set_ii)
    {
        if(isNull().isTrue())
            return BLImpl.FALSE;
        else
            return BLImpl.valueOf(mSet.containsAll(set_ii.toSet()));
    }

    public SET_II union(SET_II set_ii)
    {
        if(isNull().isTrue())
            if(set_ii.isNull().isTrue())
                return this;
            else
                return set_ii;
        if(set_ii.isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.addAll(set_ii.toSet());
            return valueOf(hashset);
        }
    }

    public SET_II union(II ii)
    {
        if(ii.isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.add(ii);
            return new SET_IIImpl(hashset);
        }
    }

    public SET_II except(II ii)
    {
        if(isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.remove(ii);
            return new SET_IIImpl(hashset);
        }
    }

    public SET_II except(SET_II set_ii)
    {
        if(isNull().or(set_ii.isNull()).isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            Set set = set_ii.toSet();
            hashset.removeAll(set);
            return new SET_IIImpl(hashset);
        }
    }

    public SET_II intersection(SET_II set_ii)
    {
        if(isNull().or(set_ii.isNull()).isTrue())
            return nullSET_II();
        HashSet hashset = new HashSet();
        for(Iterator iterator = set_ii.toSet().iterator(); iterator.hasNext();)
        {
            II ii = (II)iterator.next();
            if(mSet.contains(ii))
                hashset.add(ii);
        }

        return valueOf(hashset);
    }

    public IVL_II hull()
    {
        throw ANYImpl.newUnsupportedException("SET<II>", "hull");
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof SET_II))
            return BLImpl.FALSE;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            SET_II set_ii = (SET_II)any;
            return BLImpl.valueOf(equalsSet(set_ii.toSet()));
        }
    }

    public String toString()
    {
        String s = null;
        if(isNull().isFalse())
        {
            s = "{";
            for(Iterator iterator = mSet.iterator(); iterator.hasNext();)
            {
                s = s + (II)iterator.next();
                if(iterator.hasNext())
                    s = s + "; ";
            }

            s = s + "}";
        } else
        {
            s = "<Null:" + nullFlavor().toString() + ">";
        }
        return s;
    }

    protected boolean verifyItem(Object obj)
    {
        return (obj instanceof II) && ((II)obj).nonNull().isTrue();
    }

    public int hashCode()
    {
        return super.hashCode();
    }

    public static SET_II nullSET_II(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
